/* 快慢双指针删除倒数第n个结点
 * https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* removeNthFromEnd(struct ListNode* head, int n){
    struct ListNode *fast = head, *slow = head;
    while (n-- > 0) fast = fast->next;
    if (fast == NULL) return head->next; // 倒数第n个就是head
    while (fast != NULL && fast->next != NULL) {
        fast = fast->next;
        slow = slow->next;
    }
    slow->next = slow->next->next;
    return head;
}